#pragma once
#include <cassert>
#include <iostream>
#include <random>
#include <type_traits>

template <typename T>
void random_uniform(T *d_out, const T min, const T max, const int N,
                    const int seed) {
    std::mt19937 gen;
    gen.seed(seed);

    std::uniform_real_distribution<float> dist(
        static_cast<float>(min),
        static_cast<float>(max)); // 生成 1 到 100 之间的随机整数

    for (int i = 0; i < N; i++) {
        d_out[i] = static_cast<T>(dist(gen));
    }
}
template <typename T>
void generate(T *d_in, const int start, const int stop, const int step = 1) {
    assert(start <= stop);
    int idx = 0;
    for (int i = start; i < stop; i += step) {
        d_in[idx++] = i;
    }
}

template <typename T> void show_1d(const T &container) {
    for (const auto &element : container) {
        std::cout << element << " ";
    }
    std::cout << std::endl;
}

template <typename T> void show_1d(const T *array, size_t size) {
    for (size_t i = 0; i < size; ++i) {
        std::cout << array[i] << " ";
    }
    std::cout << std::endl;
}

template <typename T> void show_1d(const std::vector<T> &vector) {
    for (const auto &element : vector) {
        std::cout << element << " ";
    }
    std::cout << std::endl;
}

template <typename T>
bool is_same_array(const std::vector<T> &v1, const std::vector<T> &v2) {
    if (v1.size() != v2.size()) {
        return false;
    }
    for (int i = 0; i < v1.size(); i++) {
        if (v1[i] != v2[i]) {
            return false;
        }
    }
    return true;
}

template <typename T>
bool is_same_array(const T *a1, const T *a2, unsigned int size) {
    for (size_t i = 0; i < size; ++i) {
        if (a1[i] != a2[i]) {
            return false;
        }
    }
    return true;
}

// 比较浮点数数组
template <typename T, typename std::enable_if<std::is_floating_point<T>::value,
                                              bool>::type = true>
bool is_same_array(const T *arr1, const T *arr2, unsigned int n) {
    for (std::size_t i = 0; i < n; ++i) {
        if (std::abs(arr1[i] - arr2[i]) > 1e-6) { // 使用 epsilon 来比较浮点数
            return false;
        }
    }
    return true;
}
